/*   The MIT License
 *   
 *   Carina Maya Exporter
 *   Copyright (c) 2010-2011 Zdravko Velinov
 *   
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 *
 *   The above copyright notice and this permission notice shall be included in
 *   all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *   THE SOFTWARE.
 */

#ifndef _CES_TRANSLATOR_HH_
#define _CES_TRANSLATOR_HH_

#include <maya/MPxFileTranslator.h>
#include <maya/MIntArray.h>
#include <maya/MMatrix.h>
#include <maya/MDagPath.h>

#include <fstream>

#include "carina/common/containers.hh"
#include "carina/common/ces-file.hh"

using namespace Carina;

class CarinaMayaTranslator: public MPxFileTranslator
{
public:
    virtual bool haveReadMethod() const;
    virtual bool canBeOpened() const;
    virtual MStatus reader(const MFileObject &file, const MString &optionsString, FileAccessMode mode);

    virtual bool haveWriteMethod() const;
    virtual MStatus writer(const MFileObject &file, const MString &optionsString, FileAccessMode mode);

    virtual MString defaultExtension() const;
    virtual MString filter() const;
    virtual MPxFileTranslator::MFileKind identifyFile(const MFileObject &file, const char *buffer, short size) const;

    static void* create() { return new CarinaMayaTranslator; }
private:
    MStatus exportSelection(CESFile& ces_file);
    MStatus exportAll(CESFile& ces_file);

    MStatus readMesh(CESMesh& ces_mesh, MObject& dag_path);
    MStatus readSkin(DataVector<CESSkinData>& skin_data, MObject& skin_obj, MObject& mesh_obj);
    MStatus readSkeletalAnimation(CESMesh& ces_mesh, MObject& skin_obj);
    MStatus readMaterial(CESMesh& ces_mesh, const MIntArray& poly_vert_count, MObject& mesh);
};

void MatrixToDQ(const MMatrix& tmat, float* nd, float* d);

#endif /* _CES_TRANSLATOR_HH_ */
